package DBLayer;

import ModelLayer.Offer;
import ModelLayer.Order;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.fail;

public class DBOrderTest {
    @Test
    public void testGetAllOrders() throws Exception {
        ArrayList<Order> orderList = new ArrayList<Order>();
        DBOrder dbOrd = new DBOrder();
        orderList = dbOrd.getAllOrders(false);

        if (orderList != null){
            for (Order ord1 : orderList)
                System.out.println("idOrder " + ord1.getIdOrder() + " idOffer :" + ord1.getOffer().getIdOffer() + " createdDate " + ord1.getCreatedDate() + " paymentDeadline :" + ord1.getPaymentDeadline() + " status: " + ord1.getStatusOrder());

        }
        else fail();
    }

    @Test
    public void testFindOrderId() throws Exception {
        DBOrder dbOrd = new DBOrder();
        Order ord = dbOrd.findOrderId("711", false);

       if (ord != null){
           System.out.println("OrderId has been found");
           System.out.println("IdOrder : " + ord.getIdOrder() + " createdDate : " + ord.getCreatedDate());
           }
       else fail();

    }

    @Test
    public void testInsertOrder() throws Exception {
        Order ord = new Order();

        String idOff = "301";

        ord.setIdOrder("nextIdOrder");
        ord.setOffer(new Offer(idOff));
        ord.setPaymentDeadline("14112013");
        ord.setStatusOrder("Pending");
        ord.setCreatedDate("11112011");

        DBOrder dbOrd = new DBOrder();
        int i = dbOrd.insertOrder(ord);

        if(i == 1){
            System.out.println("Added");
        }
        else fail();
    }


    @Test
    public void testUpdateOrder() throws Exception {
        Order ord = new Order();
        DBOrder dbOrd = new DBOrder();

        ord.setPaymentDeadline("15-12-2010");

        String idOrder = "802";
        String paymentDeadline = "16-12-2010";
        //ord = dbOrd.updateOrder(new Order(idOrder, paymentDeadline));

        int i = dbOrd.updateOrder(ord);

    }

    @Test
    public void testDelete() throws Exception {
        Order ord = new Order();
        DBOrder dbOrd = new DBOrder();
        ord = dbOrd.findOrderId("805", false);

        if (ord != null){
        int i = dbOrd.deleteOrder("805");

        }
        else fail();
    }
}